package acwing;

import java.io.*;
import java.util.*;

public class ac867 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static int n;

    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    static void divide(int x) {
        for (int i = 2; i <= x / i; i ++ ) {
            if (x % i == 0) {
                int s = 0;
                while (x % i == 0) {
                    x /= i;
                    s ++ ;
                }
                out.println(i + " " + s);
            }
        }
        if ( x > 1) out.println(x + " " + "1");
        out.println();
    }
    public static void main(String[] args) throws IOException {
        n = cin();
        for (int i = 0; i < n; i ++ ) {
            int x = cin();
            divide(x);
        }
//        out.println();
        out.close();
    }

}